package com.books.mapper.admin;

import com.books.model.entity.backcontroller.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/9/26 19:35
 * @Version 1.0
 */
@Mapper
public interface AdminMapper {
    /**
     * 查询所有管理员
     * @return
     */
    @Select("select * from admin")
    List<Admin> findAll();

    @Select("select * from admin where people_id=#{peopleId}")
    Admin findAdminByPeopleId(Integer peopleId);

    /**
     * 根据账号查询管理员
     * @return
     */
    @Select("select * from admin where account=#{account}")
    Admin findByAccount(String account);

    /**
     * 根据用户名(昵称)查询管理员
     * @return
     */
    @Select("select * from admin where nick_name=#{nickName}")
    List<Admin> findByNickName(String nickName);

    @Select("select * from admin where admin_id=#{adminId}")
    Admin findByAdminId(Integer adminId);

    /**
     * 根据账号修改昵称,密码,权限(权限只能是Ⅲ级管理员修改)
     * @param admin
     * @param account
     */
    @Update("Update admin set people_id=#{admin.peopleId},nick_name=#{admin.nickName},password=#{admin.password},power_id=#{admin.powerId} where account=#{account}")
    void updateByAccount(Admin admin,String account);

    /**
     * 根据管理员id删除
     * @param adminId
     */
    @Delete("delete from admin where admin_id=#{adminId}")
    void delByAdminId(Integer adminId);

    @Insert("insert into admin values(null,#{peopleId},#{nickName},#{account},#{password},#{powerId})")
    void addAdmin(Admin admin);

}
